<div class="main"> 
<?php $paginationControl = $this->paginationControl($this->paginator, 'Sliding', '/index/paginator-search.phtml') ?>
<?php if (count($this->paginator)) { ?>
<div class="search-noti">Có <?php echo $this->count?> kết quả được tìm thấy</div>
        <div id="list-result" >
         <?php 
                $modelR = new RemoveCircumflex();
                $modelF = new FilmInfoModel();
                foreach($this->paginator  as $res){
                $film = $modelF->getFilmById($res->film_id);
                if($film){
                    $film = $film[0];
                    $type = explode('|',$film['type']);
                    $name_types = explode('|',$film['name_types']);
                    for($i = 0;$i < count($name_types); $i++){
                            $name_types[$i] = explode('-',$name_types[$i]);
                    };
                
                $search = strtolower($this->search);
                $field_names = $res->getDocument()->getFieldNames();
                $ep = 0;
                if($field_names[3] != null){//Kiem tra xem doi tuong co thuoc tinh des_eps hay khong?             
                    $des_eps = $res->des_eps;
                    $temp_des = str_replace('|','',$des_eps);
                    $pos = strpos($des_eps, $search);//Xac dinh vi tri chuoi tim kiem khi con |
                    if($pos != false){
                    $temp_pos =  strpos($temp_des, $search);// Xac dinh vi tri tim kiem khi bo |
                    $ep = $pos - $temp_pos+1; //Tap phim can tim   
                    }
                    //C?t l?y bài hát tìm du?c cho hi?n th? ra
                    if($ep != 0){
                    $name_ep = explode ('#|#', $film['des_eps']);
                    $name_ep = $name_ep[$ep-1]." | ";
                    }else {
                        $name_ep = "";
                        $ep = 1;
                    }
                }
            ?>
            <div class="item-result">
                <h3><a href="/app/<?php echo $modelR->rewrite($film['name']);?>/detail/<?php echo $film['id']?>-<?php echo $modelR->rewrite($film['title_vi']);?>.html#ep<?php echo $ep;?>"><?php echo $name_ep.$film['title_vi']?></a></h3>
                 <a>
                    <?php echo $film['national']?>
                </a>
                <p>Thể loại: <?php $dem = 0;for($j = 0; $j < count($name_types);$j++){ for($k = 1; $k <count($type);$k++){if($name_types[$j][0] == $type[$k]){ if($dem > 0) echo ' , ';echo "<a href='#'>".$name_types[$j][1]."</a>";$dem++;}}}?> | Lượt xem: <?php echo $film['hits']?></p>
               
            </div>
            <?php }}?>   
            <div class="clear"></div>       
        </ul>
        <div class="pagi-control" >
        <?php echo $paginationControl; ?>
        </div>
<?php }else{?>
    <div class="search-noti">Không có kết quả được tìm thấy</div>
<?php }?>
</div>
